/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author owtee
 */
@Entity
@Table(name = "users")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Users.findAll", query = "SELECT u FROM Users u"),
    @NamedQuery(name = "Users.findByUserId", query = "SELECT u FROM Users u WHERE u.userId = :userId"),
    @NamedQuery(name = "Users.findByUserPwd", query = "SELECT u FROM Users u WHERE u.userPwd = :userPwd"),
    @NamedQuery(name = "Users.findByEmpFirstName", query = "SELECT u FROM Users u WHERE u.empFirstName = :empFirstName"),
    @NamedQuery(name = "Users.findByEmpLastName", query = "SELECT u FROM Users u WHERE u.empLastName = :empLastName"),
    @NamedQuery(name = "Users.findByTelephone", query = "SELECT u FROM Users u WHERE u.telephone = :telephone"),
    @NamedQuery(name = "Users.findByAdminFlag", query = "SELECT u FROM Users u WHERE u.adminFlag = :adminFlag"),
    @NamedQuery(name = "Users.findByMsgFlag", query = "SELECT u FROM Users u WHERE u.msgFlag = :msgFlag"),
    @NamedQuery(name = "Users.findByMenuRole", query = "SELECT u FROM Users u WHERE u.menuRole = :menuRole"),
    @NamedQuery(name = "Users.findByActiveFlag", query = "SELECT u FROM Users u WHERE u.activeFlag = :activeFlag"),
    @NamedQuery(name = "Users.findByCreateUser", query = "SELECT u FROM Users u WHERE u.createUser = :createUser"),
    @NamedQuery(name = "Users.findByCreateDate", query = "SELECT u FROM Users u WHERE u.createDate = :createDate"),
    @NamedQuery(name = "Users.findByModifyUser", query = "SELECT u FROM Users u WHERE u.modifyUser = :modifyUser"),
    @NamedQuery(name = "Users.findByModifyDate", query = "SELECT u FROM Users u WHERE u.modifyDate = :modifyDate")})
public class Users implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 10)
    @Column(name = "User_Id")
    private String userId;
    @Size(max = 10)
    @Column(name = "User_Pwd")
    private String userPwd;
    @Size(max = 50)
    @Column(name = "Emp_FirstName")
    private String empFirstName;
    @Size(max = 50)
    @Column(name = "Emp_LastName")
    private String empLastName;
    @Size(max = 20)
    @Column(name = "Telephone")
    private String telephone;
    @Column(name = "Admin_Flag")
    private Boolean adminFlag;
    @Column(name = "Msg_Flag")
    private Boolean msgFlag;
    @Size(max = 2)
    @Column(name = "Menu_Role")
    private String menuRole;
    @Column(name = "Active_Flag")
    private Boolean activeFlag;
    @Size(max = 10)
    @Column(name = "Create_User")
    private String createUser;
    @Column(name = "Create_Date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date createDate;
    @Size(max = 10)
    @Column(name = "Modify_User")
    private String modifyUser;
    @Column(name = "Modify_Date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date modifyDate;
    @JoinColumn(name = "Com_Id", referencedColumnName = "Com_Id")
    @ManyToOne(optional = false)
    private Company comId;
    @JoinColumn(name = "Div_Id", referencedColumnName = "Div_Id")
    @ManyToOne(optional = false)
    private Division divId;
    @JoinColumn(name = "Dep_Id", referencedColumnName = "Dep_Id")
    @ManyToOne(optional = false)
    private Department depId;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "msgUser")
    private Collection<Jobs> jobsCollectionMsgUser;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "requestUser")
    private Collection<Jobs> jobsCollectionRequestUser;

    public Users() {
    }

    public Users(String userId) {
        this.userId = userId;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getUserPwd() {
        return userPwd;
    }

    public void setUserPwd(String userPwd) {
        this.userPwd = userPwd;
    }

    public String getEmpFirstName() {
        return empFirstName;
    }

    public void setEmpFirstName(String empFirstName) {
        this.empFirstName = empFirstName;
    }

    public String getEmpLastName() {
        return empLastName;
    }

    public void setEmpLastName(String empLastName) {
        this.empLastName = empLastName;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    public Boolean getAdminFlag() {
        return adminFlag;
    }

    public void setAdminFlag(Boolean adminFlag) {
        this.adminFlag = adminFlag;
    }

    public Boolean getMsgFlag() {
        return msgFlag;
    }

    public void setMsgFlag(Boolean msgFlag) {
        this.msgFlag = msgFlag;
    }

    public String getMenuRole() {
        return menuRole;
    }

    public void setMenuRole(String menuRole) {
        this.menuRole = menuRole;
    }

    public Boolean getActiveFlag() {
        return activeFlag;
    }

    public void setActiveFlag(Boolean activeFlag) {
        this.activeFlag = activeFlag;
    }

    public String getCreateUser() {
        return createUser;
    }

    public void setCreateUser(String createUser) {
        this.createUser = createUser;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public String getModifyUser() {
        return modifyUser;
    }

    public void setModifyUser(String modifyUser) {
        this.modifyUser = modifyUser;
    }

    public Date getModifyDate() {
        return modifyDate;
    }

    public void setModifyDate(Date modifyDate) {
        this.modifyDate = modifyDate;
    }

    public Company getComId() {
        return comId;
    }

    public void setComId(Company comId) {
        this.comId = comId;
    }

    public Division getDivId() {
        return divId;
    }

    public void setDivId(Division divId) {
        this.divId = divId;
    }

    public Department getDepId() {
        return depId;
    }

    public void setDepId(Department depId) {
        this.depId = depId;
    }

    @XmlTransient
    public Collection<Jobs> getJobsCollectionMsgUser() {
        return jobsCollectionMsgUser;
    }

    public void setJobsCollectionMsgUser(Collection<Jobs> jobsCollection) {
        this.jobsCollectionMsgUser = jobsCollection;
    }

    @XmlTransient
    public Collection<Jobs> getJobsCollectionRequestUser() {
        return jobsCollectionRequestUser;
    }

    public void setJobsCollectionRequestUser(Collection<Jobs> jobsCollection1) {
        this.jobsCollectionRequestUser = jobsCollection1;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (userId != null ? userId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Users)) {
            return false;
        }
        Users other = (Users) object;
        if ((this.userId == null && other.userId != null) || (this.userId != null && !this.userId.equals(other.userId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Users[ userId=" + userId + " ]";
    }
    
    public String getName() {
        if(empFirstName == null) {
            empFirstName = "";
        }
        if(empLastName == null) {
            empLastName = "";
        }
        
        return empFirstName + " " + empLastName;
    }
}
